<template>
	<view class="h-shop-filter">
		<view v-for="(item,index) in db" :key='index' @click="C_navItem(index)">
			<block v-if="item.name == '综合'">
				<text>{{item.name}}</text>
				<image v-if="item.active" :src="require('./img/a1.png')" mode="widthFix"></image>
				<image v-else :src="require('./img/a.png')" mode="widthFix"></image>
			</block>
			<block v-else>
				<text>{{item.name}}</text>
				<image v-if="item.active == null" :src="require('./img/b.png')" mode="widthFix"></image>
				<image v-if="item.active == true" :src="require('./img/b1.png')" mode="widthFix"></image>
				<image v-if="item.active == false" :src="require('./img/b2.png')" mode="widthFix"></image>
			</block>
		</view>
		<view>
			<image class="toggle" :src="require('./img/toggle.png')" mode="widthFix" @click="togglelist"></image>
		</view>
		
	</view>
</template>

<script>
	export default {
		name:"h-shop-filter",
		data() {
			return {
				db:[
					{name:'综合',active:true},
					{name:'价格',active:null},
					{name:'销量',active:null},
				],
			};
		},
		methods:{
			togglelist(){
				this.$set(this.$parent,'togglelist',!this.$parent.togglelist)
			},
			C_navItem(index){
				if(index == 0){
					console.log('综合排序');
					this.db[1].active = this.db[2].active = null
				}
				if(index == 1){
					console.log('价格排序');
					this.db[0].active = false
					this.db[2].active = null
				}
				if(index == 2){
					console.log('销量排序');
					this.db[0].active = false
					this.db[1].active = null
				}
				this.isnav(index)
				this.$emit('C_navItem',{obj:this.db,index})
			},
			isnav(index){
				let thisActive = this.db[index].active
				if(thisActive == null){
					this.db[index].active = true
				}else{
					this.db[index].active = !this.db[index].active
				}
			}
		}
	}
</script>

<style lang="scss">
	.h-shop-filter{
		background-color: #FFFFFF;
		padding: 20rpx;
		position: sticky;
		top: 105rpx;
		
		display: flex;
		justify-content: space-between;
		>view{
			width: 25%;
			display: flex;
			align-items: center;
			justify-content: center;
			
			image{
				display: inline-block;
				width: 12rpx;
				margin-left: 15rpx;
			}
			&:nth-child(-n+3){
				image{
					max-height: 24rpx;
				}
			}
			.toggle{
				width: 35rpx;
				height: 75rpx;
			}
		}
	}
</style>
